<template>
  <div class="teacher-student-management">
    <div class="page-header">
      <h2>学生管理</h2>
    </div>

    <!-- 筛选条件 -->
    <el-card class="filter-card" shadow="never">
      <el-form :model="filterForm" :inline="true" class="filter-form">
        <el-form-item label="学期">
          <el-select
            v-model="filterForm.semester"
            placeholder="请选择学期"
            clearable
            style="width: 200px"
            @change="handleSemesterChange"
          >
            <el-option label="2024春季" value="2024春季" />
            <el-option label="2024秋季" value="2024秋季" />
            <el-option label="2025春季" value="2025春季" />
            <el-option label="2025秋季" value="2025秋季" />
          </el-select>
        </el-form-item>
        
        <el-form-item label="学生姓名">
          <el-input
            v-model="filterForm.stuName"
            placeholder="请输入学生姓名"
            clearable
            style="width: 200px"
            @clear="() => pagination.currentPage = 1"
          />
        </el-form-item>

        <el-form-item label="班级">
          <el-select
            v-model="filterForm.clazzName"
            placeholder="请选择班级"
            clearable
            style="width: 200px"
            @change="() => pagination.currentPage = 1"
          >
            <el-option
              v-for="clazz in clazzList"
              :key="clazz"
              :label="clazz"
              :value="clazz"
            />
          </el-select>
        </el-form-item>
        
        <el-form-item>
          <el-button type="primary" @click="handleFilter">
            <el-icon><Search /></el-icon>
            查询
          </el-button>
          <el-button @click="handleReset">
            <el-icon><Refresh /></el-icon>
            重置
          </el-button>
        </el-form-item>
      </el-form>
    </el-card>

    <!-- 统计概览 -->
    <el-row :gutter="20" class="stats-overview">
      <el-col :span="8">
        <el-card class="stat-card" shadow="hover">
          <div class="stat-content">
            <div class="stat-icon">
              <el-icon><User /></el-icon>
            </div>
            <div class="stat-info">
              <div class="stat-value">{{ filteredStudents.length }}</div>
              <div class="stat-label">学生总数</div>
            </div>
          </div>
        </el-card>
      </el-col>
      
      <el-col :span="8">
        <el-card class="stat-card" shadow="hover">
          <div class="stat-content">
            <div class="stat-icon">
              <el-icon><School /></el-icon>
            </div>
            <div class="stat-info">
              <div class="stat-value">{{ filteredClazzCount }}</div>
              <div class="stat-label">班级数量</div>
            </div>
          </div>
        </el-card>
      </el-col>
      
      <el-col :span="8">
        <el-card class="stat-card" shadow="hover">
          <div class="stat-content">
            <div class="stat-icon">
              <el-icon><Avatar /></el-icon>
            </div>
            <div class="stat-info">
              <div class="stat-value">{{ maleCount }} / {{ femaleCount }}</div>
              <div class="stat-label">男生 / 女生</div>
            </div>
          </div>
        </el-card>
      </el-col>
    </el-row>

    <!-- 学生列表 -->
    <el-card class="student-card" shadow="hover">
      <template #header>
        <div class="card-header">
          <span>学生列表</span>
          <div class="header-actions">
            <el-button type="success" @click="exportStudents">
              <el-icon><Download /></el-icon>
              导出数据
            </el-button>
          </div>
        </div>
      </template>
      
      <el-table
        :data="paginatedStudents"
        v-loading="loading"
        stripe
        border
        style="width: 100%"
      >
        <el-table-column type="index" label="序号" width="80" align="center" />
        <el-table-column prop="stuNo" label="学号" width="120" align="center" />
        <el-table-column prop="stuName" label="姓名" width="120" align="center" />
        <el-table-column prop="stuSex" label="性别" width="100" align="center">
          <template #default="scope">
            <el-tag :type="scope.row.stuSex === 1 ? 'primary' : 'danger'">
              {{ scope.row.stuSex === 1 ? '男' : '女' }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="stuAge" label="年龄" width="80" align="center" />
        <el-table-column prop="clazzName" label="班级" width="200" />
        <el-table-column prop="grade" label="年级" width="100" align="center" />
        <el-table-column prop="dept" label="院系" width="150" />
        <el-table-column prop="stuPhone" label="联系电话" width="150" align="center" />
        <el-table-column prop="stuEmail" label="邮箱" min-width="180" />
        <el-table-column label="操作" width="150" fixed="right" align="center">
          <template #default="scope">
            <el-button
              type="primary"
              size="small"
              @click="handleViewDetail(scope.row)"
            >
              查看详情
            </el-button>
          </template>
        </el-table-column>
      </el-table>

      <!-- 分页 -->
      <div class="pagination-container">
        <el-pagination
          v-model:current-page="pagination.currentPage"
          v-model:page-size="pagination.pageSize"
          :page-sizes="[10, 20, 50, 100]"
          :total="filteredStudents.length"
          layout="total, sizes, prev, pager, next, jumper"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </div>
    </el-card>

    <!-- 学生详情对话框 -->
    <el-dialog
      v-model="detailDialogVisible"
      title="学生详情"
      width="600px"
    >
      <div class="student-detail">
        <el-descriptions :column="2" border>
          <el-descriptions-item label="学号">
            {{ studentDetail.stuNo }}
          </el-descriptions-item>
          <el-descriptions-item label="姓名">
            {{ studentDetail.stuName }}
          </el-descriptions-item>
          <el-descriptions-item label="性别">
            <el-tag :type="studentDetail.stuSex === 1 ? 'primary' : 'danger'">
              {{ studentDetail.stuSex === 1 ? '男' : '女' }}
            </el-tag>
          </el-descriptions-item>
          <el-descriptions-item label="年龄">
            {{ studentDetail.stuAge }}
          </el-descriptions-item>
          <el-descriptions-item label="班级">
            {{ studentDetail.clazzName }}
          </el-descriptions-item>
          <el-descriptions-item label="年级">
            {{ studentDetail.grade }}
          </el-descriptions-item>
          <el-descriptions-item label="院系" :span="2">
            {{ studentDetail.dept }}
          </el-descriptions-item>
          <el-descriptions-item label="联系电话" :span="2">
            {{ studentDetail.stuPhone }}
          </el-descriptions-item>
          <el-descriptions-item label="邮箱" :span="2">
            {{ studentDetail.stuEmail }}
          </el-descriptions-item>
          <el-descriptions-item label="QQ" :span="2">
            {{ studentDetail.stuQq || '未填写' }}
          </el-descriptions-item>
          <el-descriptions-item label="备注" :span="2">
            {{ studentDetail.stuRemark || '无' }}
          </el-descriptions-item>
        </el-descriptions>
      </div>
      
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="detailDialogVisible = false">关闭</el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>

<script setup>
import { ref, reactive, onMounted, computed } from 'vue'
import { ElMessage } from 'element-plus'
import { Search, Refresh, Download, User, School, Avatar } from '@element-plus/icons-vue'
import { getTeacherStudents } from '../api/teacherUser'
import ExcelJS from 'exceljs'

// 筛选表单
const filterForm = reactive({
  semester: '2024春季',
  stuName: '',
  clazzName: ''
})

// 加载状态
const loading = ref(false)

// 学生数据
const students = ref([])

// 详情对话框
const detailDialogVisible = ref(false)
const studentDetail = ref({})

// 分页
const pagination = reactive({
  currentPage: 1,
  pageSize: 20
})

// 班级列表（用于筛选）
const clazzList = computed(() => {
  const clazzes = new Set()
  students.value.forEach(student => {
    if (student.clazzName) {
      clazzes.add(student.clazzName)
    }
  })
  return Array.from(clazzes).sort()
})

// 过滤后的学生列表
const filteredStudents = computed(() => {
  let result = students.value

  // 按姓名筛选
  if (filterForm.stuName) {
    result = result.filter(student =>
      student.stuName && student.stuName.includes(filterForm.stuName)
    )
  }

  // 按班级筛选
  if (filterForm.clazzName) {
    result = result.filter(student =>
      student.clazzName === filterForm.clazzName
    )
  }

  return result
})

// 分页后的学生列表
const paginatedStudents = computed(() => {
  const start = (pagination.currentPage - 1) * pagination.pageSize
  const end = start + pagination.pageSize
  return filteredStudents.value.slice(start, end)
})

// 过滤后的班级数量统计
const filteredClazzCount = computed(() => {
  const clazzes = new Set()
  filteredStudents.value.forEach(student => {
    if (student.clazzName) {
      clazzes.add(student.clazzName)
    }
  })
  return clazzes.size
})

// 男女生统计
const maleCount = computed(() => {
  return filteredStudents.value.filter(s => s.stuSex === 1).length
})

const femaleCount = computed(() => {
  return filteredStudents.value.filter(s => s.stuSex === 0).length
})

// 获取学生数据
const fetchStudents = async () => {
  loading.value = true
  
  try {
    const user = JSON.parse(localStorage.getItem('user') || '{}')
    console.log('===== 前端调试信息 =====')
    console.log('用户信息:', user)
    
    // 获取教师ID - 兼容多种字段名
    const teacherId = user.teacherId || user.teacher_id || user.teId || user.id
    console.log('教师ID:', teacherId)
    console.log('学期:', filterForm.semester)
    
    if (!teacherId) {
      ElMessage.error('请先登录')
      console.error('未找到教师ID，用户信息:', user)
      return
    }

    console.log('调用API: getTeacherStudents(' + teacherId + ', ' + (filterForm.semester || 'advanced') + ')')
    const response = await getTeacherStudents(teacherId, filterForm.semester || 'advanced')
    console.log('API响应:', response)
    
    if (response && response.data) {
      const previousCount = students.value.length
      students.value = response.data
      console.log('学生数量:', students.value.length)
      
      if (students.value.length === 0) {
        ElMessage.info('该学期暂无学生数据')
      } else if (previousCount === 0) {
        // 首次加载时显示成功消息
        ElMessage.success(`成功加载 ${students.value.length} 名学生`)
      } else if (previousCount !== students.value.length) {
        // 学生数量变化时显示
        ElMessage.info(`当前学期有 ${students.value.length} 名学生`)
      }
      // 如果数量没变，不显示消息
    } else {
      students.value = []
      ElMessage.warning('未获取到学生数据')
    }
    
  } catch (error) {
    console.error('获取学生列表失败:', error)
    ElMessage.error('获取学生列表失败: ' + (error.message || '未知错误'))
    students.value = []
  } finally {
    loading.value = false
  }
}

// 学期改变时重新加载数据
const handleSemesterChange = () => {
  console.log('学期改变:', filterForm.semester)
  pagination.currentPage = 1
  fetchStudents()
}

// 筛选（姓名、班级）- 仅前端过滤
const handleFilter = () => {
  pagination.currentPage = 1 // 重置到第一页
  console.log('应用筛选条件 - 姓名:', filterForm.stuName, '班级:', filterForm.clazzName)
  
  // 筛选只在前端进行，不需要重新加载数据
  const count = filteredStudents.value.length
  if (filterForm.stuName || filterForm.clazzName) {
    ElMessage.info(`筛选结果: ${count} 名学生`)
  }
}

// 重置筛选
const handleReset = () => {
  filterForm.semester = '2024春季'
  filterForm.stuName = ''
  filterForm.clazzName = ''
  pagination.currentPage = 1
  fetchStudents()
}

// 查看详情
const handleViewDetail = (row) => {
  studentDetail.value = { ...row }
  detailDialogVisible.value = true
}

// 导出学生数据
const exportStudents = async () => {
  try {
    if (!filteredStudents.value || filteredStudents.value.length === 0) {
      ElMessage.warning('暂无学生数据可导出')
      return
    }

    // 获取当前用户信息
    const user = JSON.parse(localStorage.getItem('user') || '{}')
    const teacherName = user.teName || user.name || '教师'
    
    // 创建工作簿
    const workbook = new ExcelJS.Workbook()
    workbook.creator = teacherName
    workbook.created = new Date()
    
    // ================ 工作表1：学生列表 ================
    const sheet1 = workbook.addWorksheet('学生列表')
    
    // 设置列宽
    sheet1.columns = [
      { width: 8 },   // 序号
      { width: 12 },  // 学号
      { width: 12 },  // 姓名
      { width: 8 },   // 性别
      { width: 8 },   // 年龄
      { width: 20 },  // 班级
      { width: 12 },  // 年级
      { width: 18 },  // 院系
      { width: 15 },  // 联系电话
      { width: 25 },  // 邮箱
      { width: 15 }   // QQ
    ]
    
    // 添加标题（合并单元格）
    sheet1.mergeCells('A1:K1')
    const titleCell = sheet1.getCell('A1')
    titleCell.value = `${teacherName}的学生名单 - ${filterForm.semester}学期`
    titleCell.font = { bold: true, size: 16, color: { argb: 'FF2C3E50' } }
    titleCell.alignment = { vertical: 'middle', horizontal: 'center' }
    titleCell.fill = {
      type: 'pattern',
      pattern: 'solid',
      fgColor: { argb: 'FFF0F2F5' }
    }
    sheet1.getRow(1).height = 35
    
    // 添加表头
    const headerRow = sheet1.addRow(['序号', '学号', '姓名', '性别', '年龄', '班级', '年级', '院系', '联系电话', '邮箱', 'QQ'])
    headerRow.height = 28
    headerRow.font = { bold: true, size: 11, color: { argb: 'FFFFFFFF' } }
    headerRow.alignment = { vertical: 'middle', horizontal: 'center' }
    headerRow.fill = {
      type: 'pattern',
      pattern: 'solid',
      fgColor: { argb: 'FF5470C6' }
    }
    
    // 添加学生数据
    filteredStudents.value.forEach((student, index) => {
      const row = sheet1.addRow([
        index + 1,
        student.stuNo || '',
        student.stuName || '',
        student.stuSex === 1 ? '男' : (student.stuSex === 0 ? '女' : ''),
        student.stuAge || '',
        student.clazzName || '',
        student.grade || '',
        student.dept || '',
        student.stuPhone || '',
        student.stuEmail || '',
        student.stuQq || ''
      ])
      
      row.height = 22
      row.alignment = { vertical: 'middle', horizontal: 'center' }
      
      // 序号列加粗
      row.getCell(1).font = { bold: true }
      
      // 邮箱列左对齐
      row.getCell(10).alignment = { vertical: 'middle', horizontal: 'left' }
      
      // 性别列根据性别添加颜色标签
      const sexCell = row.getCell(4)
      if (student.stuSex === 1) {
        sexCell.fill = {
          type: 'pattern',
          pattern: 'solid',
          fgColor: { argb: 'FFE1F3FF' }
        }
        sexCell.font = { color: { argb: 'FF409EFF' }, bold: true }
      } else if (student.stuSex === 0) {
        sexCell.fill = {
          type: 'pattern',
          pattern: 'solid',
          fgColor: { argb: 'FFFEF0F0' }
        }
        sexCell.font = { color: { argb: 'FFF56C6C' }, bold: true }
      }
      
      // 斑马纹效果
      if (index % 2 === 1) {
        for (let i = 1; i <= 11; i++) {
          const cell = row.getCell(i)
          if (!cell.fill || !cell.fill.fgColor) {
            cell.fill = {
              type: 'pattern',
              pattern: 'solid',
              fgColor: { argb: 'FFF9FAFB' }
            }
          }
        }
      }
    })
    
    // 添加边框
    sheet1.eachRow((row, rowNumber) => {
      if (rowNumber >= 1) {
        row.eachCell((cell) => {
          cell.border = {
            top: { style: 'thin', color: { argb: 'FFD0D0D0' } },
            left: { style: 'thin', color: { argb: 'FFD0D0D0' } },
            bottom: { style: 'thin', color: { argb: 'FFD0D0D0' } },
            right: { style: 'thin', color: { argb: 'FFD0D0D0' } }
          }
        })
      }
    })
    
    // ================ 工作表2：统计信息 ================
    const sheet2 = workbook.addWorksheet('统计信息')
    
    // 设置列宽
    sheet2.columns = [
      { width: 25 },  // 统计项
      { width: 20 }   // 统计值
    ]
    
    // 添加标题
    sheet2.mergeCells('A1:B1')
    const statTitleCell = sheet2.getCell('A1')
    statTitleCell.value = '学生统计信息'
    statTitleCell.font = { bold: true, size: 16, color: { argb: 'FF2C3E50' } }
    statTitleCell.alignment = { vertical: 'middle', horizontal: 'center' }
    statTitleCell.fill = {
      type: 'pattern',
      pattern: 'solid',
      fgColor: { argb: 'FFF0F2F5' }
    }
    sheet2.getRow(1).height = 35
    
    // 添加空行
    sheet2.addRow([])
    
    // 添加统计数据
    const stats = [
      { label: '学期', value: filterForm.semester || 'advanced' },
      { label: '学生总数', value: filteredStudents.value.length },
      { label: '班级数量', value: filteredClazzCount.value },
      { label: '男生人数', value: maleCount.value },
      { label: '女生人数', value: femaleCount.value },
      { label: '导出时间', value: new Date().toLocaleString('zh-CN') },
      { label: '导出教师', value: teacherName }
    ]
    
    stats.forEach((stat, index) => {
      const row = sheet2.addRow([stat.label, stat.value])
      row.height = 28
      
      // 标签列样式
      row.getCell(1).font = { bold: true, size: 12 }
      row.getCell(1).alignment = { vertical: 'middle', horizontal: 'right' }
      row.getCell(1).fill = {
        type: 'pattern',
        pattern: 'solid',
        fgColor: { argb: 'FFF5F7FA' }
      }
      
      // 值列样式
      row.getCell(2).font = { size: 12, color: { argb: 'FF2C3E50' } }
      row.getCell(2).alignment = { vertical: 'middle', horizontal: 'left' }
      
      // 添加边框
      row.eachCell((cell) => {
        cell.border = {
          top: { style: 'thin', color: { argb: 'FFD0D0D0' } },
          left: { style: 'thin', color: { argb: 'FFD0D0D0' } },
          bottom: { style: 'thin', color: { argb: 'FFD0D0D0' } },
          right: { style: 'thin', color: { argb: 'FFD0D0D0' } }
        }
      })
    })
    
    // 添加空行
    sheet2.addRow([])
    sheet2.addRow([])
    
    // 添加班级分布
    sheet2.mergeCells(`A${sheet2.rowCount + 1}:B${sheet2.rowCount + 1}`)
    const clazzTitleCell = sheet2.getCell(`A${sheet2.rowCount}`)
    clazzTitleCell.value = '班级分布'
    clazzTitleCell.font = { bold: true, size: 14, color: { argb: 'FF2C3E50' } }
    clazzTitleCell.alignment = { vertical: 'middle', horizontal: 'center' }
    clazzTitleCell.fill = {
      type: 'pattern',
      pattern: 'solid',
      fgColor: { argb: 'FFE8F4F8' }
    }
    sheet2.getRow(sheet2.rowCount).height = 30
    
    // 添加班级分布表头
    const clazzHeaderRow = sheet2.addRow(['班级名称', '学生人数'])
    clazzHeaderRow.height = 25
    clazzHeaderRow.font = { bold: true, size: 11, color: { argb: 'FFFFFFFF' } }
    clazzHeaderRow.alignment = { vertical: 'middle', horizontal: 'center' }
    clazzHeaderRow.fill = {
      type: 'pattern',
      pattern: 'solid',
      fgColor: { argb: 'FF70AD47' }
    }
    
    // 计算班级分布
    const clazzDistribution = {}
    filteredStudents.value.forEach(student => {
      const clazzName = student.clazzName || '未分配班级'
      clazzDistribution[clazzName] = (clazzDistribution[clazzName] || 0) + 1
    })
    
    // 添加班级分布数据
    Object.entries(clazzDistribution)
      .sort((a, b) => b[1] - a[1]) // 按人数降序排序
      .forEach(([clazzName, count], index) => {
        const row = sheet2.addRow([clazzName, count])
        row.height = 22
        row.getCell(1).alignment = { vertical: 'middle', horizontal: 'left' }
        row.getCell(2).alignment = { vertical: 'middle', horizontal: 'center' }
        row.getCell(2).font = { bold: true, color: { argb: 'FF409EFF' } }
        
        // 斑马纹效果
        if (index % 2 === 1) {
          row.fill = {
            type: 'pattern',
            pattern: 'solid',
            fgColor: { argb: 'FFF9FAFB' }
          }
        }
        
        // 添加边框
        row.eachCell((cell) => {
          cell.border = {
            top: { style: 'thin', color: { argb: 'FFD0D0D0' } },
            left: { style: 'thin', color: { argb: 'FFD0D0D0' } },
            bottom: { style: 'thin', color: { argb: 'FFD0D0D0' } },
            right: { style: 'thin', color: { argb: 'FFD0D0D0' } }
          }
        })
      })
    
    // 生成文件名
    const semester = filterForm.semester || '2024春季'
    const clazzFilter = filterForm.clazzName ? `_${filterForm.clazzName}` : ''
    const nameFilter = filterForm.stuName ? `_${filterForm.stuName}` : ''
    const fileName = `${teacherName}_学生名单_${semester}${clazzFilter}${nameFilter}_${new Date().toLocaleDateString().replace(/\//g, '-')}.xlsx`
    
    // 导出文件
    const buffer = await workbook.xlsx.writeBuffer()
    const blob = new Blob([buffer], { 
      type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' 
    })
    const url = window.URL.createObjectURL(blob)
    const link = document.createElement('a')
    link.href = url
    link.download = fileName
    link.click()
    window.URL.revokeObjectURL(url)
    
    ElMessage.success(`成功导出 ${filteredStudents.value.length} 名学生数据！`)
  } catch (error) {
    console.error('导出学生数据失败:', error)
    ElMessage.error('导出学生数据失败: ' + error.message)
  }
}

// 分页大小改变
const handleSizeChange = (size) => {
  pagination.pageSize = size
  pagination.currentPage = 1
}

// 页码改变
const handleCurrentChange = (page) => {
  pagination.currentPage = page
}

// 组件挂载时获取数据
onMounted(() => {
  fetchStudents()
})
</script>

<style scoped>
.teacher-student-management {
  background: #f5f7fa;
  padding: 20px;
  font-family: 'PingFang SC', 'Microsoft YaHei', sans-serif;
  box-sizing: border-box;
}

.page-header {
  margin-bottom: 32px;
  text-align: center;
}

.page-header h2 {
  margin: 0;
  color: #2c3e50;
  font-size: 28px;
  font-weight: 600;
  letter-spacing: 1px;
}

.filter-card {
  margin-bottom: 20px;
  border-radius: 8px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
  border: 1px solid #e4e7ed;
  background: #ffffff;
}

.filter-card :deep(.el-card__body) {
  padding: 20px;
}

.filter-form {
  margin-bottom: 0;
}

.filter-form :deep(.el-form-item) {
  margin-bottom: 16px;
  margin-right: 24px;
}

.filter-form :deep(.el-form-item__label) {
  font-weight: 600;
  color: #2c3e50;
  font-size: 14px;
}

.stats-overview {
  margin-bottom: 20px;
}

.stat-card {
  border-radius: 8px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
  border: 1px solid #e4e7ed;
  background: #ffffff;
  transition: all 0.3s ease;
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

.stat-card :deep(.el-card__body) {
  padding: 20px;
}

.stat-content {
  display: flex;
  align-items: center;
  gap: 16px;
}

.stat-icon {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  font-size: 24px;
}

.stat-info {
  flex: 1;
}

.stat-value {
  font-size: 32px;
  font-weight: 700;
  color: #2c3e50;
  line-height: 1;
  margin-bottom: 8px;
}

.stat-label {
  font-size: 14px;
  color: #606266;
  font-weight: 500;
}

.student-card {
  border-radius: 8px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
  border: 1px solid #e4e7ed;
  background: #ffffff;
  overflow: hidden;
}

.student-card :deep(.el-card__header) {
  background: #f5f7fa;
  border-bottom: 1px solid #ebeef5;
  padding: 16px 20px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.card-header span {
  color: #2c3e50;
  font-weight: 600;
  font-size: 16px;
}

.header-actions .el-button {
  border-radius: 4px;
  font-weight: 500;
  padding: 8px 16px;
  transition: all 0.3s ease;
}

.student-card :deep(.el-table) {
  border-radius: 8px;
  overflow: hidden;
}

.student-card :deep(.el-table__header) {
  background: #f5f7fa;
}

.student-card :deep(.el-table th) {
  background: transparent;
  color: #2c3e50;
  font-weight: 600;
  font-size: 14px;
  border-bottom: 1px solid #ebeef5;
  padding: 12px;
}

.student-card :deep(.el-table td) {
  padding: 12px;
  border-bottom: 1px solid #ebeef5;
  color: #606266;
  font-size: 14px;
}

.student-card :deep(.el-table__row:hover) {
  background: #f5f7fa;
}

.pagination-container {
  display: flex;
  justify-content: center;
  margin-top: 20px;
  padding: 20px 0;
}

.pagination-container :deep(.el-pagination) {
  gap: 8px;
}

.pagination-container :deep(.el-pagination .btn-prev),
.pagination-container :deep(.el-pagination .btn-next),
.pagination-container :deep(.el-pagination .el-pager li) {
  border-radius: 4px;
  font-weight: 500;
}

/* 学生详情样式 */
.student-detail {
  padding: 20px 0;
}

.student-detail :deep(.el-descriptions) {
  border-radius: 8px;
  overflow: hidden;
}

.student-detail :deep(.el-descriptions__header) {
  background: #f5f7fa;
  padding: 16px 20px;
  border-bottom: 1px solid #ebeef5;
}

.student-detail :deep(.el-descriptions__title) {
  color: #2c3e50;
  font-weight: 600;
  font-size: 16px;
}

.student-detail :deep(.el-descriptions__body) {
  background: #ffffff;
}

.student-detail :deep(.el-descriptions-item__label) {
  background: #fafafa;
  color: #606266;
  font-weight: 600;
  width: 120px;
}

.student-detail :deep(.el-descriptions-item__content) {
  color: #2c3e50;
  padding: 12px 20px;
}

.dialog-footer {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  padding-top: 16px;
}

.dialog-footer .el-button {
  border-radius: 4px;
  font-weight: 500;
  padding: 10px 20px;
  transition: all 0.3s ease;
}

/* 对话框样式优化 */
:deep(.el-dialog) {
  border-radius: 8px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
  border: 1px solid #e4e7ed;
}

:deep(.el-dialog__header) {
  background: #f5f7fa;
  border-radius: 8px 8px 0 0;
  padding: 16px 20px;
  border-bottom: 1px solid #ebeef5;
}

:deep(.el-dialog__title) {
  color: #2c3e50;
  font-weight: 600;
  font-size: 16px;
}

:deep(.el-dialog__body) {
  padding: 20px;
}

:deep(.el-dialog__footer) {
  padding: 16px 20px;
  background: #f5f7fa;
  border-radius: 0 0 8px 8px;
  border-top: 1px solid #ebeef5;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .teacher-student-management {
    padding: 16px;
  }
  
  .page-header h2 {
    font-size: 24px;
  }
  
  .stats-overview {
    margin-bottom: 16px;
  }
  
  .stat-content {
    flex-direction: column;
    text-align: center;
    gap: 12px;
  }
  
  .stat-icon {
    width: 50px;
    height: 50px;
    font-size: 20px;
  }
  
  .stat-value {
    font-size: 24px;
  }
  
  .filter-form :deep(.el-form-item) {
    margin-right: 0;
    width: 100%;
  }
  
  .filter-form :deep(.el-input),
  .filter-form :deep(.el-select) {
    width: 100%;
  }
}

@media (max-width: 480px) {
  .teacher-student-management {
    padding: 12px;
  }
  
  .page-header h2 {
    font-size: 20px;
  }
  
  .filter-card :deep(.el-card__body) {
    padding: 16px;
  }
  
  .stat-card :deep(.el-card__body) {
    padding: 16px;
  }
  
  .stat-icon {
    width: 40px;
    height: 40px;
    font-size: 18px;
  }
  
  .stat-value {
    font-size: 20px;
  }
}
</style>


